<template>
    <div class="acc">
        <el-breadcrumb separator="/" style="margin-bottom:20px;">
            <el-breadcrumb-item :to="{ path: '/' }">
                <i class="el-icon-setting" style="margin-right:4px;"></i>首页</el-breadcrumb-item>
            <el-breadcrumb-item>账号管理</el-breadcrumb-item>
        </el-breadcrumb>
        <router-link to="/accountAdd" class="nav-a">
            <el-button type="primary" style="margin-bottom:15px;">
                账号添加
            </el-button>
        </router-link>
        <el-table :data="tableData" border style="width: 100%" v-loading.lock="loading">
            <el-table-column prop="belong_name" label="酒店" width="180">
            </el-table-column>
            <el-table-column prop="username" label="账号" width="180">
            </el-table-column>
            <el-table-column prop="user_type" :formatter="rankFiltered" label="级别">
            </el-table-column>
            <el-table-column label="操作" width="140">
                <template scope="scope">
                    <el-button size="small" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
                    <el-button size="small" type="danger" @click="handleDelete(scope.$index, scope.row)">删除</el-button>
                </template>
            </el-table-column>
        </el-table>
    </div>
</template>
<script>
export default {
    data() {
        return {
            tableData: [],
            loading:true
        }
    },
    mounted() {
        this.$http.get(this.ajaxUrl() + "/user/groupAccount?id=" + this.$store.state.grogshop.hotelId).then((response) => {
            let data = response.data;
            for (let i = 0; i < data.length; i++) {
                this.tableData.push(data[i])
            }

            this.loading = false
        })
    },
    methods: {
        getSummaries(row, column){
            
        },
        handleEdit(index,row){
            this.$store.commit("accoutComplie",{
                data:row,
            })

            this.$router.push('/accountUpdate');
        },
        handleDelete(index, row) {
            let _this = this;
            this.$http.get(this.ajaxUrl() + "/user/userDelete?id=" + row.id).then((response) => {
                if (response.data.type === 'succeed') {
                    this.$message({
                        message: '删除成功！',
                        type: 'success',
                        duration: 1000,
                        onClose: function () {
                        }
                    });
                    this.tableData.splice(index,1);
                } else {
                    this.$message.error('删除失败！');
                }
            })
        },
        rankFiltered(row, column){
            if(row.user_type === 0){
                return "超级管理员"
            }else if(row.user_type === 1){
                return "集团管理员"
            }
        }
    }
}
</script>
<style>
.acc {
    width: 800px;
}
.nav-a {
    color: #fff!important;
}
</style>


